<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>Insert title here</title>
</head>
<body>
	<div class="layui-collapse">
		<div class="layui-colla-item">
			<h2 class="layui-colla-title">员工信息-查询条件</h2>
			<div class="layui-colla-content layui-show">

				<fieldset class="layui-elem-field layui-field-title"
					style="margin: 25px;">
					<legend>员工部门信息-查询条件</legend>
					<div class="layui-field-box">
						<form class="layui-form layui-form-pane">
							<div class="layui-form-item">
								<label class="layui-form-label">员工编号</label>
								<div class="layui-input-inline">
									<input type="text" name="code" placeholder="请输入员工编号"
										autocomplete="off" class="layui-input">
								</div>
								<label class="layui-form-label">员工姓名</label>
								<div class="layui-input-inline">
									<input type="text" name="name" placeholder="请输入员工名称"
										autocomplete="off" class="layui-input">
								</div>
								&nbsp;&nbsp;&nbsp;&nbsp; <span> <input type="button"
									lay-submit lay-filter="search" value="查询" class="layui-btn" />
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									<button type="button" class="layui-btn" onclick="openAdd()">添加</button>
								</span>
							</div>

							<!-- 							<input type="hidden" name="action" value="list"> -->
							<input type="hidden" name="action" value="page"> 
							<input type="hidden" name="pageIndex" value="1"> 
							<input type="hidden" name="pageLimit" value="10">
						</form>
					</div>
				</fieldset>
			</div>
		</div>
	</div>

	<table class="layui-table">
		<colgroup>
			<col width="5%">
			<col width="5%">
			<col width="5%">
			<col width="6%">
			<col width="6%">
			<col width="18%">

		</colgroup>
		<thead>
			<tr>
				<th>序号</th>
				<th>编号</th>
				<th>姓名</th>
				<th>部门编号</th>
				<th>部门名称</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="user_tbody">

		</tbody>
	</table>
	<div id="pageInfoUser" style="text-align: right; padding-right: 30px;"></div>
	<script type="text/javascript">
		element.render();
		formSubmit("/employee", "submit(search)", "json", function(data) {
			var curr = $("input[name='pageIndex']").val();
			var limit = $("input[name='pageLimit']").val();
			setPageInfo('pageInfoUser', data.count, curr, limit, function(obj,
					first) {
				$("input[name='pageIndex']").val(obj.curr);
				$("input[name='pageLimit']").val(obj.limit);
				if (!first) {
					refresh()
				}
			})
			var html = "";
			$.each(data.list, function(i, dom) {
				var name = dom.name ? dom.name : '';
				var tel = dom.tel ? dom.tel : '';
				var codeDept=dom.codeDept ? dom.codeDept : '';
				var nameDept=dom.nameDept? dom.nameDept:'';
				var d = {
					i : i + 1,
					code : dom.code,
					name : name,
					codeDept : codeDept,
					nameDept : nameDept
				}
				var laytpl = layui.laytpl;
				html += laytpl($("#tradd").html()).render(d);
				//html+=getlaytpl("#tradd",d)
			})
			$("#user_tbody").html(html);
			layer.msg("查询成功");
		})
		
		refresh();
		function refresh(){
			$("input[value='查询']").click();
		}
		function openAdd(){
// 			layer.open({
// 				type:2,
// 				area:['750px','500px'],
// 				fixed:false,
// 				maxmin:true,
// 				content:base.app+"/web/page/department/add.jsp"
// 			})
		openLayer("/web/page/employee/add.jsp",refresh);
		}
		function del(code){
			openConfirm(function(){
				ajax("/employee",{action:"del",code:code},'text',function(data){
					
					if(data=="exist"){
						layer.msg("删除失败，部门存在员工！")
					}else if(data==1){
						layer.msg("删除成功",{time:1000},refresh)
					}
				})
			})
		}
		
		function openUpd(code){
			openLayer("/web/page/employee/upd.jsp?code="+code,refresh);
		}
		
		function resetCode(code){
			openConfirm(function(){
				ajax('/employee',{action:"resetPass",code:code},'text',function(data){
					console.log(data)
					if(data==1){
						layer.msg("密码已重置");
					}else{
						layer.msg("重置失败");
					}
				})
			})
		}
		function updCode(code){
			openLayer("/web/page/employee/updCode.jsp?code="+code,refresh);
		}
		function updDept(code){
			openLayer("/web/page/employee/updDpm.jsp?code="+code,refresh);
		}
		function openPic(code){
			openLayer("/web/page/employee/userPic.jsp?code="+code,refresh);
		}
	</script>
	<script type="text/html" id="tradd">
		<tr>
		<td>{{ d.i }}</td>
		<td>{{ d.code }}</td>
		<td>{{ d.name }}</td>
		<td>{{ d.codeDept }}</td>
		<td>{{ d.nameDept }}</td>
		<td>
			<input type='button' class='layui-btn layui-btn-sm' value='修改' onclick='openUpd("{{d.code}}")'>
			<a href='javascript:del("{{d.code}}");' class='layui-btn layui-btn-sm layui-btn-danger'>
				<i class='layui-icon layui-icon-delete'></i>
			</a>&nbsp;&nbsp;
			
			<input type='button' value='设置部门' class='layui-btn layui-btn-sm' onclick="updDept('{{d.code}}');" >
			<input type='button' value='重置密码' class='layui-btn layui-btn-sm' onclick="resetCode('{{d.code}}');" >
			<input type='button' value='修改密码' class='layui-btn layui-btn-sm' onclick="updCode('{{d.code}}');" >
			<input type='button' value='上传头像' class='layui-btn layui-btn-sm' onclick="openPic('{{d.code}}');" >
		</td>
</tr>
	</script>
</body>
</html>